/**
 * @Author: XJH
 * @Description: TODO
 * @Date: 2025/10/23 21:42
 * @Version: 1.0
 */

import java.util.HashMap;

/**
 * @Author: XJH
 * @Description: TODO
 * @Date: 2025/10/23 21:42
 * @Version: 1.0
 */
public class Longest_substring_without_repeated_characters {
    public int lengthOfLongestSubstring(String s) {
        if(s.length()<0)return 0;
        HashMap<Character, Integer> map = new HashMap<>();
          int left=0;
           int max=0;
           for(int i=0;i<s.length();i++){
               if(map.containsKey(s.charAt(i))){
                   left=Math.max(left,map.get(s.charAt(i)) + 1);
               }
               map.put(s.charAt(i),i);
               max=Math.max(max,i-left+1);
           }
          return max;
    }
    public static void main(String[] args) {
        String s = "abcabcbb";
        int result = new Longest_substring_without_repeated_characters().lengthOfLongestSubstring(s);
        System.out.println(result);
    }
}
